Microsoft C file routines by function see p. 88-c for explanation of---> err inc Directory Control - uses char *getcwd (char *pathbuf, int buflen) NULL* int chdir (char *pathname) -1* int mkdir (char *pathname) -1* int rmdir (char *pathname) -1* File Handling - uses 1=, 2=, 3=, 4= & , 5= int umask (int pmode) 1,4 int rename (char *oldname, char *newname) ~0* 1 or 2 int remove/unlink (char *pathname) -1* 1 or 2 char *mktemp (char *template) NULL 1 int access (char *pathname, int access-mode) -1* 1 int chmod (char *pathname, int pmode) -1* 1,4 int stat (char *pathname, struct stat *buffer) -1* 4 int fstat (int handle, struct stat *buffer) -1* 4 int isatty (int handle) 1 int setmode (int handle, int translation-mode) -1* 1,3 int locking (int handle, int lock-mode, long nbyte) -1* 1,5 long filelength (int handle) -1L* 1 int chsize (int handle, long size) -1* 1 Low Level I/O - uses , & maybe for "EOF", etc. also: 1=, 2=, 3= & int open (char *pathname, int oflag[, int pmode]) -1* 1[,3] int sopen (char *pathname, int oflag, int shflag[, int pmode]) -1* 1,2[,3] int creat (char *pathname, int pmode) -1* 1,3 int dup (int handle) -1* int dup2 (int handle, int dup-handle) -1* int close (int handle) -1* long lseek (int handle, long offset, int origin) -1L* long tell (int handle) -1L* int eof (int handle) -1* int read (int handle, char *buffer, unsigned int count) 0/-1* int write (int handle, char *buffer, unsigned int count) -1* 88-a _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _+ Stream I/O - uses also: 1= (for UNIX), -or- (for ANSI C) FILE *fopen (char *pathname, char *type) NULL FILE *freopen (char *pathname, char *type, FILE stream) NULL FILE *tmpfile (void) NULL FILE *fdopen (int handle, char *type) NULL int fclose (FILE *stream) EOF int fcloseall (void) EOF void setbuf (FILE *stream, char *buffer) int setvbuf (FILE *stream, char *buffer, int buftype, int buflen) ~0 void rewind (FILE *stream) int fseek (FILE *stream, long offset, int origin) ~0 or ? long ftell (FILE *stream) -1L int fileno (FILE *stream) n/a or ? int feof (FILE *stream) int ferror (FILE *stream) void clearerr (FILE *stream) char *tempnam (char *dir, char *prefix) NULL char *tmpnam (char *string) NULL int rmtmp (void) int fflush (FILE *stream) EOF int flushall (void) int fread (char *buffer, int it-size, int it-count, FILE *stream) < it-count int getc/fgetc (FILE *stream) ?EOF int getw (FILE *stream) ?EOF char *fgets (char *buffer, int bufsize, FILE *stream) ?NULL int fscanf (FILE *stream, char *format[, args...]) EOF! int ungetc (int c, FILE *stream) EOF int fwrite (char *buffer, int it-size, int it-count, FILE *stream) < it-count int putc/fputc (int c, FILE *stream) ?EOF int putw (int binint, FILE *stream) ?EOF int fputs (char *string, FILE *stream) EOF int fprintf (FILE *stream, char *format[, args...]) int vfprintf (FILE *stream, char *format, va_list arg-ptr) 1 88-b _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _+ (stdin/stdout stream-routines) int getchar/fgetchar (void) ?EOF char *gets (char *buffer) ?NULL int scanf (char *format[, args...]) EOF! int putchar/fputchar (int c) ?EOF int puts (char *string) EOF int printf (char *format[, args...]) int vprintf (char *format, va_list arg-ptr) 1 (buffer i/o stream-routines) int sscanf (char *buffer, char *format[, args...]) EOF! int sprintf (char *buffer, char *format[, args...]) int vsprintf (char *buffer, char *format, va_list arg-ptr) 1 Console and port I/O - uses & for "EOF", etc. int getch (void) int getche (void) char *cgets (char *str) int cscanf (char *format[, args...]) EOF! int ungetch (int c) EOF void putch (int c) void cputs (char *str) int cprintf (char *format[, args...]) int kbhit (void) int inp (unsigned port) int outp (unsigned port, int value) ----------------- err = error indication (if any); '*' signifies that errno is set; ~0 means non-zero; lone '?' means that return value may be undefined; ?XXX means that XXX may (or not) indicate an error -check further with eof, feof, ferror; EOF! means that EOF is always end-of-file; EOF is defined as -1 in stdio.h (along with NULL, etc.) note: to use errno, must define errno, & maybe sys_nerr, sys_errlist[]. inc = #include-file requirements - see key at top of each section. 88-c _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _+ Microsoft C string & buffer manipulation routines declares all functions; declares only buffer functions. Copy - returns pointer to destination (except memccpy) char *strcpy (dst,src) copies src to dst, including \0 char *strncpy (dst,src,n) copies exactly n chars, \0-padding if n > len(src) char *memcpy (dst,src,n) copies n bytes from src to dst (overlap handled ok) char *memccpy (dst,src,c,n) same, except stops after 1st c (if any) note: memccpy returns pointer to next char in dst following c (or NULL) void movedata (src-seg,src-off,dst-seg,dst-off,n) copies far-data note: movedata useful in small and medium models, (memcpy ok for large) char *strdup (str) allocates (malloc) & copies to new storage (NULL = error) Compare - returns <0, 0, >0 depending on lexicographic order - case-insensitive routines treat all alpha as lower case int strcmp (str1,str2) compare str1 : str2 int stricmp/strcmpi (str1,str2) same, case-insensitive int strncmp (str1,str2,n) compares 1st n chars int *strnicmp (str1,str2,n) same, case-insensitive int memcmp (buf1,buf2,n) compares n bytes buf1 : buf2 int memicmp (buf1,buf2,n) same, case-insensitive 88-d _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _+ String & buffer routines (continued) Examine char *strstr (str,key) points to 1st key-string in str (or NULL) char *strchr (str,c) points to 1st c in str (or NULL) - allows \0 char *strrchr (str,c) points to last c (or NULL) char *memchr (buf,c,n) points to 1st c in 1st n bytes of buf (or NULL) char *strpbrk (str,set) points to 1st char in str from set (or NULL) - no \0 int strlen (str) length, not including \0 (i.e., index of the \0) unsigned strspn (str,set) index of 1st char NOT in set (=len of str prefix from set) unsigned strcspn (str,set) index of 1st char in set (=len of str prefix NOT from set) Modify - returns pointer to given string/buffer or destination string/buffer char *strlwr (str) converts any upper case to lower char *strupr (str) converts any lower case to upper char *strrev (str) reverses the string leaving \0 untouched char *strset (str,c) sets all except \0 to c char *strnset (str,c,n) sets at most n chars to c, not passing \0 char *memset (buf,c,n) sets 1st n bytes of buf to c char *strcat (dst,src) appends src to dst char *strncat (dst,src,n) appends at most n chars of src to dst char *strerror (str) concatenates last error, \n to str (allows str=NULL) note: strerror requires definition of errno, sys_nerr, sys_errlist[]. Examine & Mmodify char *strtok (str,set) points to 1st token in str (or NULL) " (NULL,set) points to next token in previous str (or NULL) note: set (the delimiters) need not be same on all calls also: strtok skips leading delims, replaces delims with \0 88-e _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _+